﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABClist
{
    class ABClist
    {
        static void Main()
        {
            String sorceText = String.Empty;
            sorceText = EnterText();
            PrintAbcList(sorceText);
            Console.ReadKey();
        }
        public static String EnterText()
        {
            String processingText = String.Empty;
            Console.Write(Literals.ENTER);
            processingText = Console.ReadLine();
            return processingText;
        }
        public static void PrintAbcList(String sorceText)
        {
            String[] list = sorceText.Split(new Char[] { ' ', ',', '.', ':', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            SortTextArray(list);

            for (int i = 0; i < list.Length; i++)
            {
                if ((i > 0) && !(list[i-1][0] == list[i][0]))
                {
                    Console.WriteLine();
                    Console.Write("{0} ", list[i][0]);
                }
                else if (i == 0)
                {
                    Console.WriteLine();
                    Console.Write("{0} ", list[i][0]);
                }
                Console.WriteLine("\t {0} ", list[i]);
            }
        }
        public static void SortTextArray(String[] list)
        {
            bool optim = true;
            for (Int32 i = 0; i < list.Length || optim; i++)
            {
                optim = false;
                for (Int32 j = 0; j < list.Length - 1; j++)
                {
                    Char firstLetter = list[j][0];
                    if (firstLetter > list[j + 1][0])
                    {
                        String temp = list[j];
                        list[j] = list[j + 1];
                        list[j + 1] = temp;
                        optim = true;
                    }
                }
            }
        }
    }
}
